package com.dq.domain.evaluation;

import com.dq.domain.subscribe.Subscribe;
import com.dq.domain.sys.user.user.BossUser;
import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;
import com.dq.domain.record.ServiceRecord;
import com.dq.domain.sys.user.user.StaffUser;
import com.dq.domain.sys.user.user.WxUser;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import java.util.List;

/**
 * @author liuhui
 * @date 2019/11/20 0020 13:59:01
 */
@Data
@Entity
@ApiModel("评价记录")
public class EvaluationRecord extends BaseEntity implements VO.ToVO {

    @ApiModelProperty("预约记录")
    @ManyToOne
    protected Subscribe subscribe;

    @ApiModelProperty("评价内容")
    protected String content;

    @ApiModelProperty("平均分")
    protected Long averageScore;




    @Data
    @ApiModel(value = "评价记录视图")
    public static class Vo implements VO {
        @ApiModelProperty("id")
        protected Long id;
        protected Long staffUserId;
        @ApiModelProperty("技师名称")
        protected String staffUserName;
        protected Long wxUserId;
        @ApiModelProperty("顾客名称")
        protected String wxUserName;

        @ApiModelProperty("服务开始时间")
        protected String beginTime;

        @ApiModelProperty("服务结束时间")
        protected String endTime;

        @ApiModelProperty("平均分")
        protected Long averageScore;
        @ApiModelProperty("评价内容")
        protected String content;

        @ApiModelProperty("服务项目名")
        protected String projectName;

        @ApiModelProperty("预约单编号")
        protected String subscribeNo;
        @ApiModelProperty(value = "创建时间")
        private String createTime;
        @ApiModelProperty(value = "修改时间")
        private String lastModifyTime;
        @ApiModelProperty(value = "创建者id")
        private Long createUserId;
        @ApiModelProperty(value = "创建者name")
        private String createUserName;
        @ApiModelProperty(value = "修改者id")
        private Long updateUserId;
        @ApiModelProperty(value = "修改者name")
        private String updateUserName;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id= this.getId();
        BossUser staffUser = this.getSubscribe().getTechnicianUser();
        vo.staffUserId = staffUser!= null?staffUser.getId():null;
        vo.staffUserName =staffUser!= null?staffUser.getUserRealcName():"";
        WxUser wxUser = (WxUser) this.getSubscribe().getWxUser();
        vo.wxUserId = wxUser != null ?wxUser.getId():null;
        vo.wxUserName =wxUser != null ? wxUser.getUserRealcName():"";
        vo.beginTime = fmt(this.getSubscribe().getBeginTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.endTime = fmt(this.getSubscribe().getEndTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.averageScore = fmt(this.getAverageScore());
        vo.content = fmt(this.content);
        vo.projectName = this.getSubscribe() != null ? this.getSubscribe().getProjectName():"";
        vo.subscribeNo = this.getSubscribe() != null ? this.getSubscribe().getSubscribeNo():"";

        vo.createTime = TimeUtil.longToString(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.lastModifyTime = TimeUtil.longToString(this.lastModifyTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.createUserId = this.createUser == null ? null : this.createUser.getId();
        vo.createUserName = this.createUser == null ? null : this.createUser.getUserRealcName();
        vo.updateUserId = this.updateUser == null ? null : this.updateUser.getId();
        vo.updateUserName = this.updateUser == null ? null : this.updateUser.getUserRealcName();
        return vo;
    }

    @Data
    @ApiModel("门店端返回实体视图")
    public static class OrgEvaluationRecordVo{
        @ApiModelProperty("id")
        protected Long id;
        protected Long staffUserId;
        @ApiModelProperty("技师名称")
        protected String technicianName;
        protected Long wxUserId;
        @ApiModelProperty("顾客名称")
        protected String customerName;

        @ApiModelProperty("开始时间")
        protected String beginTime;

        @ApiModelProperty("结束时间")
        protected String endTime;

        @ApiModelProperty("平均分")
        protected Long averageScore;
    }

    @Data
    @ApiModel("门店端评价详情返回视图")
    public static class OrgEvaluationDetailVo{
        @ApiModelProperty("顾客建议")
        protected String cusSugContent;
        @ApiModelProperty("评价详情列表")
        protected List<EvaluationRecordTemplate.Vo> evaluationRecordTemplateVo;
    }

    public OrgEvaluationRecordVo toOrgEvaluationRecordVo(){
        EvaluationRecord.OrgEvaluationRecordVo orgEvaluationRecordVo = new EvaluationRecord.OrgEvaluationRecordVo();
        orgEvaluationRecordVo.id= this.getId();
        BossUser staffUser = this.getSubscribe().getTechnicianUser();
        orgEvaluationRecordVo.staffUserId = staffUser.getId();
        orgEvaluationRecordVo.technicianName =staffUser.getUserRealcName();
        WxUser wxUser = (WxUser) this.getSubscribe().getWxUser();
        orgEvaluationRecordVo.wxUserId = wxUser.getId();
        orgEvaluationRecordVo.customerName =wxUser.getUserRealcName();
        orgEvaluationRecordVo.beginTime = fmt(this.getSubscribe().getBeginTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS);
        orgEvaluationRecordVo.endTime = fmt(this.getSubscribe().getEndTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS);
        orgEvaluationRecordVo.averageScore = fmt(this.getAverageScore());
        return orgEvaluationRecordVo;
    }

    public OrgEvaluationDetailVo toOrgEvaluationDetailVo(List<EvaluationRecordTemplate.Vo> evaluationRecordTemplateVo){
        EvaluationRecord.OrgEvaluationDetailVo orgEvaluationDetailVo = new EvaluationRecord.OrgEvaluationDetailVo();
        orgEvaluationDetailVo.cusSugContent = fmt(this.getContent());
        orgEvaluationDetailVo.evaluationRecordTemplateVo = evaluationRecordTemplateVo;
        return orgEvaluationDetailVo;
    }

    @Data
    @ApiModel("pc评价详情返回视图")
    public static class PcEvaluationDetail{
        protected Long staffUserId;
        @ApiModelProperty("技师名称")
        protected String staffUserName;
        protected Long wxUserId;
        @ApiModelProperty("顾客名称")
        protected String wxUserName;

        @ApiModelProperty("服务开始时间")
        protected String beginTime;

        @ApiModelProperty("服务结束时间")
        protected String endTime;

        @ApiModelProperty("平均分")
        protected Long averageScore;
        @ApiModelProperty("评价内容")
        protected String content;

        @ApiModelProperty("服务项目名")
        protected String projectName;

        @ApiModelProperty(value = "创建时间")
        private String createTime;
    }

    public PcEvaluationDetail toPcEvaluationDetail(){
        PcEvaluationDetail vo = new PcEvaluationDetail();
        BossUser staffUser = this.getSubscribe().getTechnicianUser();
        vo.staffUserId = staffUser!= null?staffUser.getId():null;
        vo.staffUserName =staffUser!= null?staffUser.getUserRealcName():"";
        WxUser wxUser = (WxUser) this.getSubscribe().getWxUser();
        vo.wxUserId = wxUser != null ?wxUser.getId():null;
        vo.wxUserName =wxUser != null ? wxUser.getUserRealcName():"";
        vo.beginTime = fmt(this.getSubscribe().getBeginTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.endTime = fmt(this.getSubscribe().getEndTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.averageScore = fmt(this.getAverageScore());
        vo.content = fmt(this.content);
        vo.projectName = this.getSubscribe() != null ? this.getSubscribe().getProjectName():"";


        vo.createTime = TimeUtil.longToString(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        return vo;
    }

}
